//
//  BMWCollectionViewCell.swift
//  BMWOpenShare
//
//  Created by Li Shengbing, (Shengbing.Li@partner.bmw.com) on 2019/6/5.
//  Copyright © 2019年 shanghai. All rights reserved.
//

import UIKit

class BMWCollectionViewCell: UICollectionViewCell {
    
    var bmwShareModel: BMWShareModel? {
        didSet {
            guard let model = bmwShareModel else {
                return
            }
            titleLabel.text = model.title
            imageV.image = BMWShareViewModel.getImageResourceFromSDKBundle(fullImageName: model.imageName)
        }
    }
    
    fileprivate lazy var titleLabel: UILabel = UILabel()
    fileprivate lazy var imageV: UIImageView = UIImageView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setupUI() {
        contentView.addSubview(imageV)
        contentView.addSubview(titleLabel)
        //contentView.backgroundColor = UIColor.randomColor()
        
        imageV.isUserInteractionEnabled = true
        imageV.contentMode = .scaleAspectFill
        imageV.layer.masksToBounds = true
        
        titleLabel.text = "微信好友"
        titleLabel.font = UIFont.systemFont(ofSize: 13)
        titleLabel.textColor = UIColor.black
        titleLabel.textAlignment = .center
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        imageV.sizeToFit()
        imageV.frame = CGRect(x: 0, y: 0, width: imageV.bounds.width, height: imageV.bounds.height)
        imageV.center.x = self.contentView.center.x
        
        titleLabel.sizeToFit()
        titleLabel.frame = CGRect(x: 0, y: imageV.frame.maxY + 8, width: self.bounds.width, height: titleLabel.bounds.height)
        titleLabel.center.x = self.imageV.center.x
    }
}


